home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacWT 0.9 / wt Source / wt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-10  |  2.5 KB  |  116 lines  |  [TEXT/CWIE]

  1. /*
  2. **  MacWT -- a 3d game engine for the Macintosh
  3. **  © 1995, Bill Hayden and Nikol Software
  4. **
  5. **  On the Internet:
  6. **  bmoc1@aol.com (my personal address)
  7. **  nikolsw@grove.ufl.edu (my school address)
  8. **    MacWT anonymous FTP site: ftp.circa.ufl.edu/pub/software/ufmug/mirrors/LocalSW/Hayden/
  9. **  http://grove.ufl.edu:80/~nikolsw (my WWW page, containing MacWT info)
  10. **
  11. **  based on wt, by Chris Laurel (claurel@mr.net)
  12. **
  13. **  This program is distributed in the hope that it will be useful,
  14. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. */
  17.  
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <math.h>
  23. #include "wt.h"
  24. #include "error.h"
  25. #include "fixed.h"
  26. #include "view.h"
  27. #include "framebuf.h"
  28. #include "texture.h"
  29. #include "table.h"
  30. #include "list.h"
  31. #include "world.h"
  32. #include "worldfile.h"
  33. #include "render.h"
  34. #include "graphics.h"
  35. #include "input.h"
  36. #include "object.h"
  37. #include "MacWT.h"
  38.  
  39.  
  40.  
  41.  
  42. void WTMain(char *WorldFile, short width, short height)
  43. {
  44.     Boolean            quit = FALSE;
  45.     Intent            *intent;
  46.     extern double    gravity;
  47.     
  48.     
  49.     while (!quit)
  50.         {
  51.         double sin_facing, cos_facing;
  52.         double fx, fy, fz;
  53.         fixed        shift = 0;
  54.  
  55.         intent = read_input_devices();
  56.         
  57.         while (intent->n_special--)
  58.             {
  59.             switch (intent->special[intent->n_special])
  60.                 {
  61.                 case INTENT_END_GAME:
  62.                     quit = TRUE;
  63.                     break;
  64.                 
  65.                 case INTENT_JUMP:
  66.                 case INTENT_ACTION4:
  67.                 case INTENT_ACTION5:
  68.                     object_apply_force(me, 0.0, 0.0, 50.0);
  69.                     break;
  70.                     
  71.                 case INTENT_ACTION1:
  72.                     shift = FIXED_HALF_PI;    // Peek left
  73.                     break;
  74.                                          
  75.                 case INTENT_ACTION2:
  76.                     shift = FIXED_PI;        // Peek behind
  77.                     break;
  78.                     
  79.                 case INTENT_ACTION3:
  80.                     shift = -FIXED_HALF_PI;    // Peek right
  81.                     break;
  82.                     
  83.                 case INTENT_GROW_V:
  84.                 case INTENT_SHRINK_V:
  85.                     break;
  86.                 }
  87.             }
  88.  
  89.         /* Determine forces on viewer. */
  90.         sin_facing = sin(me->angle);
  91.         cos_facing = cos(me->angle);
  92.         fx = cos_facing * intent->force_x - sin_facing * intent->force_y;
  93.         fy = sin_facing * intent->force_x + cos_facing * intent->force_y;
  94.         fz = gravity * me->mass;  /* gravity */
  95.  
  96.         /* Apply the forces. */
  97.         object_apply_force(me, fx, fy, fz);
  98.         object_apply_torque(me, intent->force_rotate);
  99.         object_update(me);
  100.  
  101.         object_apply_force(him, fx, fy, 0.0);
  102.         object_update(him);
  103.  
  104.         /* Determine the view. */
  105.         object_view(me, view);
  106.         
  107.         if (shift)
  108.             ShiftViewpoint(view, FIXED_ZERO, FIXED_ZERO, FIXED_ZERO, shift);
  109.  
  110.         /* Display the world. */
  111.         Render(w, view);
  112.         RefreshWTWindow();
  113.         }
  114.  
  115.     EndGraphics();
  116. }